package com.ruoyi.forApp.controller;


import com.ruoyi.forApp.domain.TeacherForApp;
import com.ruoyi.project.system.course.service.ICourseArrangeService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;

@Controller
public class TeacherControllerForApp {
    @Autowired
    private ICourseArrangeService courseArrangeService;

    @Autowired
    private IUserService userService;
    @Autowired
    private IDeptService deptService;


    @PostMapping("/getTeacherList")
    @ResponseBody
    public List<TeacherForApp> list(Long userId)
    {
        List<TeacherForApp>teacherForApps=new ArrayList<>();
        User student=userService.selectUserById(userId);
        Dept studentClass=deptService.selectDeptById(student.getDeptId());
        Dept studentSchool=deptService.findSchoolObjByDeptId(studentClass.getDeptId());
        List<User> teacherList=userService.selectTeacherList();
        for (User teacher:teacherList){
            Dept teacherSchool=deptService.findSchoolObjByDeptId(teacher.getDeptId());
            if (teacherSchool.getDeptId().equals(studentSchool.getDeptId())){
                TeacherForApp teacherForApp=new TeacherForApp();
                teacherForApp.setEmail(teacher.getEmail());
                teacherForApp.setPosition("教师");
                teacherForApp.setTeacherName(getName(teacher.getUserName()));
                teacherForApp.setTel(teacher.getPhonenumber());
                teacherForApps.add(teacherForApp);
            }
        }
        return teacherForApps;
    }

    private String getName(String name){
        return name.replaceAll("\\(.*?\\)","");
    }



}
